﻿@using Wicresoft.UnifyShow.Utility;
@using Wicresoft.UnifyShow.Business;
@{
    var taskStatus = ViewData["TaskStatus"] as EnumDataSource<EnumUtility.TaskStatus>;
    var taskTypes = ViewData["TaskType"] as EnumDataSource<EnumUtility.TaskType>;
    var taskRange = ViewData["TaskRange"] as List<PlanLocationOwner>;
    var location = ViewData["Location"] as SiteBranchModel;
    var IsGlobalConfigAdmin = (bool)ViewData["IsGlobalConfigAdmin"];
}
<div class="padding5left" id="searchContainer" style="height:100%;">
    <div id="searchParam">
        <div style="display: none;">
            <div class="left">搜索类型</div>
            <div class="right">
                <select data-search-param="SearchType" style="width: 64%;" id="searchType" onchange="toggleSearchArea()">
                    <option value="2" data-search-for="searchedTaskList">任务</option>
                    <option value="1" data-search-for="searchedPlanList">计划</option>
                </select>
            </div>
        </div>
        @*<div></div>*@
        <div>
            <div class="left">任务类型</div>
            <div class="right">
                <select data-search-param="TaskType" style="width: 64%;">
                    <option value="-1">全部</option>
                    @{ foreach (var item in taskTypes)
                       {
                        <option value="@item.EnumValue">@item.DisplayValue</option>
                       }
                    }
                </select>
            </div>
        </div>
        <div class="searchForTask">
            <div class="left statusSearch">任务状态</div>
            <div class="right statusSearch">
                <select data-search-param="TaskStatus" style="width: 64%;">
                    <option value="-1">全部</option>
                    @{ foreach (var item in taskStatus)
                       {
                        <option value="@item.EnumValue" @(item.EnumValue == (int)EnumUtility.TaskStatus.InProcess ? "selected='selected'" : "")>@item.DisplayValue</option>
                       }
                    }
                </select>
            </div>
        </div>
        <div class="searchForTask">
            <div class="left">责任人</div>
            <div class="right">
                <input type="text" style="width: 60%;" disabled="disabled" data-from="username" />
                <input type="hidden" id="responsibleID" data-from="userid" data-search-param="ResponsibleID" />
                <span class="icon-search" onclick="openResponsibleSearch();"></span>
            </div>
        </div>
        <div>
            <div class="left">查询范围</div>
            <div class="right">
                <select data-search-param="TaskRange" style="width: 64%;">
                    @*全局管理员*@
                    @if (IsGlobalConfigAdmin)
                    {
                        <option value="-1">全省</option>
                        foreach (var item in taskRange)
                        {
                        <option value="@item.LocationID">@item.Alias</option>
                        }
                    }
                    else
                    {
                        if (location != null)
                        {
                        <option value="@(location.ID)">@location.Alias</option>
                        }
                    }
                </select>
            </div>
        </div>
        <div class="searchForTask">
            <div class="left">开始时间</div>
            <div class="right">
                <input type="text" class="easyui-datebox" data-search-param="StartDate" />
            </div>
        </div>
        <div class="searchForTask">
            <div class="left">结束时间</div>
            <div class="right">
                <input class="easyui-datebox" data-search-param="EndDate" />
                <select style="width: 80px; height: 22px; vertical-align: bottom;" data-search-param="SearchDateType">
                    <option value="1">触发时间</option>
                    <option value="2" selected="selected">过期时间</option>
                </select>
            </div>
        </div>
        <div></div>
        <div>
            <div class="left">
            </div>
            <div class="right">
                <input type="button" value="搜索" class="searchBtn" onclick="SearchTask();" />
            </div>
        </div>
    </div>
    <div class="padding5 resultContainer" id="searchedPlanList" style="display: none;height:70%;">
        <table id="MySearchedPlanList" fit="true" class="" title="搜索结果" pagination="true" url="/PlanManagement/PostSearchPlan"
            fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="ID" sortable="true" width="80">计划编号</th>
                    <th field="JobName" sortable="true" width="200">计划名称</th>
                    <th field="JobType" formatter="formatType" sortable="true" width="140">计划类型</th>
                    <th field="Invalid" formatter="formatPlanStatus" sortable="true" width="60">状态</th>
                    <th field="JobOwnerName" sortable="true" width="80">创建人</th>
                </tr>
            </thead>
        </table>
    </div>
    <div class="padding5 resultContainer" id="searchedTaskList" style="display: none;height:70%;">
        <table id="MySearchedTaskList" fit="true" class="" title="搜索结果" pagination="true" url="/PlanManagement/PostSearchTask"
            fitcolumns="true" singleselect="true">
            <thead>
                <tr>
                    <th field="JobNo" sortable="true" width="120">任务编号</th>
                    <th field="TaskName" sortable="true" width="140">任务名称</th>
                    <th field="Status" formatter="formatStatus" sortable="true" width="80">任务状态</th>
                    <th field="OwnerName" sortable="true" width="80">责任人</th>
                    <th field="BeginDate" sortable="true" formatter="DateFormate" width="90">触发时间</th>
                    <th field="CompleteTime" sortable="true" formatter="DateFormate" width="90">完成时间</th>
                    <th field="EndDate" sortable="true" formatter="DateFormate" width="90">过期时间</th>
                    <th field="OverFlag" sortable="true" formatter="OverFlagRender">是否过期</th>
                </tr>
            </thead>
        </table>
    </div>
</div>
<script type="text/javascript">

    var toggleSearchArea = function () {
        var selected = $('#searchType').val();
        if (selected == "2") {//任务搜索
            $('.searchForTask').show();
        } else {
            $('.searchForTask').hide();
        }
    };

    var SearchTask = function () {
        var param = {};
        $('#searchParam').find('[data-search-param]').each(function () {
            if ($(this).hasClass('easyui-datebox')) {
                param[$(this).attr('data-search-param')] = $(this).datebox('getValue') == "" ? null : $(this).datebox('getValue');
            } else {
                param[$(this).attr('data-search-param')] = $(this).val();
            }
        });

        var searchType = $('#searchType').find('option:selected').attr('data-search-for');
        $('.resultContainer').hide();
        $('#' + searchType).show();

        if (searchType == "searchedTaskList") {
            $('#MySearchedTaskList').datagrid({
                pageList: [10],
                pageNumber: 1,
                queryParams: param,
                onLoadSuccess: function (data) {
                    $('.datagrid-btable').find('td').each(function () {
                        $(this).attr('title', $(this).text());
                    });
                },
                onDblClickRow: function (rowIndex, rowData) {
                    showModuleDialog('/PlanManagement/TaskDetail?UserRole=3&ID=' + rowData["ID"], 1080);
                }
            });

            var p2 = $('#MySearchedTaskList').datagrid('getPager');
            $(p2).pagination({
                beforePageText: '第',
                afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
                displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

            });
        }


        if (searchType == "searchedPlanList") {
            $('#MySearchedPlanList').datagrid({
                pageList: [10],
                pageNumber: 1,
                queryParams: param,
                onLoadSuccess: function (data) {
                    $('.datagrid-btable').find('td').each(function () {
                        $(this).attr('title', $(this).text());
                    });
                },
                onDblClickRow: function (rowIndex, rowData) {
                    var url = "/PlanManagement/";
                    var type = rowData["JobType"];
                    switch (type * 1) {
                        case 1:
                            url += "RoutineInspection";
                            break;
                        case 2:
                            url += "ThirdPartyInspection";
                            break;
                        case 3:
                            url += "GeneralPlan";
                            break;
                    }
                    url += "?ID=" + rowData["ID"];
                    showModuleDialog(url, 1080);
                }
            });

            var p3 = $('#MySearchedPlanList').datagrid('getPager');
            $(p3).pagination({
                beforePageText: '第',
                afterPageText: '页&nbsp;共&nbsp;{pages}&nbsp;页',
                displayMsg: '当前显示{from} - {to}&nbsp;条记录&nbsp;共&nbsp;{total}&nbsp;条记录'

            });
        }

    };

    $(function () {
        $('.easyui-datebox').datebox({
            formatter: function (date) {
                return date.formate('yyyy-MM-dd')
            }
        });

        $('.combo-text').attr('disabled', true);

        SearchTask();
    });
</script>
